package com.xunlai.infra.permission.business.dao.repository;

import com.xunlai.infra.permission.business.dao.entity.RouteStatistics;
import com.xunlai.infra.permission.storage.repository.BaseAllRoundRepository;
import org.springframework.data.jdbc.repository.query.Modifying;
import org.springframework.data.jdbc.repository.query.Query;
import org.springframework.data.repository.query.Param;

import java.util.Optional;

/**
 * @author liang
 * @date 10/7/23 11:40 PM
 */
public interface RouteStatisticsRepository extends BaseAllRoundRepository<RouteStatistics,Long> {


    @Query("update travel_route_statistics set view_number = view_number + 1 where route_id =:routeId")
    @Modifying
    void increaseViewNumber(@Param("routeId") Long routeId);

    @Query("update travel_route_statistics set forward_number = forward_number + 1 where route_id =:routeId")
    @Modifying
    void increaseForwardNumber(@Param("routeId") Long routeId);

    @Query("select id from travel_route_statistics where route_id = :routeId")
    Long findIdByRouteId(@Param("routeId") Long routeId);

    Optional<RouteStatistics> findByRouteId(Long routeId);
}
